import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import './Loader.less';
import themeColorClient from '../ChangeTheme/themeColorClient';
import request from '../Request';

const Loader = ({ spinning = true, fullScreen }) => {
  const [count, setCount] = useState(0);
  const initTheme = async () => {
    let themeColor = localStorage.getItem('themeColor');
    if (themeColor == null) {
      const result = await request.post({ url: './public/getThemeColor.do' });
      if (result.data == null || result.data == '') {
        themeColor = '#103648';
      }else {
        themeColor = result.data.value;
      }

      localStorage.setItem('themeColor', themeColor);
    }
    themeColorClient.changeColor(themeColor);

    // 更新缓存
    // const result = await request.post({ url: './public/getThemeColor.do' });
    // if (result.data != null) {
    //   localStorage.setItem('themeColor', result.data.value);
    // }
    // console.log('server', result)

  };
  useEffect(() => {
    initTheme();

  }, [count]);


  return (
    <div className='loader fullScreen'>
      <div className='warpper'>
        <div className='text'>正在加载页面中...</div>
      </div>
    </div>
  );
};

Loader.propTypes = {
  spinning: PropTypes.bool,
  fullScreen: PropTypes.bool,
};

export default Loader;
